package pl.edu.agh.inpema.core.dataBase;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.cfg.Configuration;

import pl.edu.agh.inpema.core.dataBase.dbImplementation.DBDataBaseImpl;
import pl.edu.agh.inpema.core.model.Analyzer;

public class DataBaseFactory {

	public static DataBase getDataBaseForEnvironment(Set<Analyzer> analyzers) {
		Configuration conf = new Configuration().configure();
		//conf.setProperty("hibernate.show_sql", "true");
		Set<Class> analyzerDataClasses = new HashSet<Class>();
		for (Analyzer analyzer : analyzers) {
			for (Class c : analyzer.getDataClasses()) {
				analyzerDataClasses.add(c);
			}
		}
		
		for (Class c : analyzerDataClasses) {
			conf.addClass(c);
		}
		return new DBDataBaseImpl(conf.buildSessionFactory().openSession());
	}
	
	public static DataBase getDataBase() {
		Configuration conf = new Configuration().configure();
		//conf.setProperty("hibernate.show_sql", "true");
		return new DBDataBaseImpl(conf.buildSessionFactory().openSession());
	}
	
}
